#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 110;
char s[maxn];
char decimal[]={"00123456789ABCDEF"};
bool check(long long sys,string x)
{
	for(long long i = 0;i<x.size();i++)
	{
		if(x[i]>decimal[sys]) return 0;
	}
	return 1;
}
long long change(long long sys,string x)
{
	long long ans = 0;
	for(int i = 0;i<x.size();i++)
	{
		long long t;
		if(x[i]>='0'&&x[i]<='9') t = x[i]-'0';
		else t = x[i]-'A'+10;
		ans = ans*sys+t;
	}
	return ans;
}
int main()
{
	
	while(scanf("%s",s)!=EOF)
	{
		int len = strlen(s);
		char op[3];
		string a,b,c;
		int flag = 0;
		for(int i = 0;i<len;i++)
		{
			if((s[i]>='0'&&s[i]<='9')||(s[i]>='A' && s[i]<='Z'))
			{
				if(flag==0) a += s[i];
				else if(flag==1) b += s[i];
				else if(flag==2) c += s[i]; 
			}
			else 
			{
				op[flag++] = s[i];
			}
		}
		int sign = 0;
		for(long long i=2;i<=16;i++)
		{
			if(check(i,a)&&check(i,b)&&check(i,c))
			{
				long long ansa,ansb,ansc;
				ansa = change(i,a);
				ansb = change(i,b);
				ansc = change(i,c);
				printf("%d %d %d %d\n",i,ansa,ansb,ansc);
				if(op[0]=='+'&&ansa+ansb==ansc) 
				{
					printf("%lld\n",i);
					sign = 1;
					break;
				}
				else if(op[0]=='-'&&ansa-ansb==ansc)
				{
					printf("%lld\n",i);
					sign = 1;
					break;
				}
				else if(op[0]=='*'&&ansa*ansb==ansc)
				{
					printf("%lld\n",i);
					sign = 1;
					break;
				}
				
				else if(op[0]=='/'&&ansa==ansb*ansc)
				{
					
					printf("%lld\n",i);
					sign = 1;
					break;
				}
			}
		}
		if(!sign) printf("-1\n");
	}
}
